<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>vue实现分页</title>
    <style>
        .now{
            text-decoration: underline;
        }
        .disabled{
            cursor: not-allowed;
        }
    </style>
</head>
<body>
    <div id="app">
        <div>第{{page}}页</div>
        <button v-on:click="change('-')"
                v-bind:disabled="page==1" 
                :class="{disabled: page == 1}"
        >上一页</button>
        <button 
        v-for="num in 5" 
        v-on:click="change(num)"
        v-bind:class="{now:num == page}"
        >{{num}}
        </button>
        <button v-on:click="change('+')" 
                v-bind:disabled="page==5"
                :class="{disabled: page == 5}"
        >下一页</button>
    </div>

    <script src="vue.js"></script>
    <script>
        let vm = new Vue({
            el: '#app',
            data: {
                page: 1
            },
            methods: {
                change(p){
                    if(p == '+' && this.page<5){
                        this.page ++;
                    }else if(p == '-' && this.page>1){
                        this.page --;
                    }else{
                        this.page = p;
                    }
                }
            },

        });
    </script>
</body>
</html>